package com.binance.assetservice.web.controller;

import com.binance.assetservice.api.IPortfolioApi;
import com.binance.assetservice.vo.request.portfolio.AddPortfolioRequest;
import com.binance.assetservice.vo.request.portfolio.DeletePortfolioRequest;
import com.binance.assetservice.vo.request.portfolio.GetPortfoliosRequest;
import com.binance.assetservice.vo.request.portfolio.GetWidgetPortfoliosRequest;
import com.binance.assetservice.vo.request.portfolio.UpdatePortfolioSequenceRequest;
import com.binance.assetservice.vo.request.portfolio.UpdateWidgetPortfoliosRequest;
import com.binance.assetservice.web.service.IPortfolioService;
import com.binance.master.models.APIRequest;
import com.binance.master.models.APIResponse;
import org.javasimon.aop.Monitored;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Monitored
public class PortfolioController implements IPortfolioApi {

    @Autowired
    private IPortfolioService portfolioService;

    @Override
    public APIResponse<Void> addPortfolio(@RequestBody @Validated APIRequest<AddPortfolioRequest> request)
            throws Exception {
        this.portfolioService.addPortfolio(request.getBody());
        return APIResponse.getOKJsonResult();
    }

    @Override
    public APIResponse<Void> deletePortfolio(@RequestBody @Validated APIRequest<DeletePortfolioRequest> request)
            throws Exception {
        this.portfolioService.deletePortfolio(request.getBody());
        return APIResponse.getOKJsonResult();
    }

    @Override
    public APIResponse<Void> updatePortfolioSequence(
            @RequestBody @Validated APIRequest<UpdatePortfolioSequenceRequest> request) throws Exception {
        this.portfolioService.updatePortfolioSequence(request.getBody());
        return APIResponse.getOKJsonResult();
    }


    @Override
    public APIResponse<List<String>> getPortfolios(@RequestBody @Validated APIRequest<GetPortfoliosRequest> request)
            throws Exception {
        return APIResponse.getOKJsonResult(this.portfolioService.getPortfolios(request.getBody()));
    }

    @Override
    public APIResponse<List<String>> getWidgetPortfolios(
            @RequestBody @Validated APIRequest<GetWidgetPortfoliosRequest> request) throws Exception {
        return APIResponse.getOKJsonResult(this.portfolioService.getWidgetPortfolios(request.getBody()));
    }

    @Override
    public APIResponse<Void> updateWidgetPortfolios(
            @RequestBody @Validated APIRequest<UpdateWidgetPortfoliosRequest> request) throws Exception {
        this.portfolioService.updateWidgetPortfolios(request.getBody());
        return APIResponse.getOKJsonResult();
    }

}
